package nio.bytebuffer;

import java.nio.ByteBuffer;

public class AdReadOnlyBuffer {

    public static void main(String[] args) {

        byte[] byteArrayIn = { 1, 2, 3, 4, 5 };
        ByteBuffer bytebuffer1 = ByteBuffer.wrap(byteArrayIn);
        ByteBuffer bytebuffer2 = bytebuffer1.asReadOnlyBuffer();

        System.out.println("bytebuffer1.isReadOnly()=" + bytebuffer1.isReadOnly()); // false
        System.out.println("bytebuffer2.isReadOnly()=" + bytebuffer2.isReadOnly()); // true

        bytebuffer2.rewind();
        bytebuffer2.put((byte)123); // java.nio.ReadOnlyBufferException

    }

}
